﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="index.aspx.cs" Inherits="lauimini_webform.index1" %>

<%@ Import Namespace="lauimini_webform.BLL" %>
<%@ Import Namespace="lauimini_webform.Data" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link href="Static/lib/layui-v2.6.3/css/layui.css" rel="stylesheet" />
    <link href="Static/css/public.css" rel="stylesheet" />
    <script src="Static/lib/echarts.min.js"></script>
</head>
<body>
    <div class="layuimini-container">
        <div class="layuimini-main">

            <fieldset class="table-search-fieldset">
                <legend>视图一览</legend>
                <div class="layui-row layui-col-space15">
                    <div class="layui-col-xs12 layui-col-md6">
                        <div id="echarts-records" style="background-color: #ffffff; min-height: 300px; padding: 10px">
                        </div>
                    </div>
                    <div class="layui-col-xs12 layui-col-md6">
                        <div id="echarts-pies" style="background-color: #ffffff; min-height: 300px; padding: 10px">
                        </div>
                    </div>
                </div>

            </fieldset>

            <script type="text/html" id="toolbarDemo">
                <div class="layui-btn-container">
                    <button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn" lay-event="add">添加 </button>
                    <%--<button class="layui-btn layui-btn-sm layui-btn-danger data-delete-btn" lay-event="delete"> 删除 </button>--%>
                </div>
            </script>

            <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>

            <script type="text/html" id="currentTableBar">
                <a class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="edit">编辑</a>
                <a class="layui-btn layui-btn layui-btn-xs data-count-start" lay-event="start">开始</a>
                <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delete">删除</a>
            </script>

        </div>
    </div>
    <script src="Static/lib/layui-v2.6.3/layui.js"></script>

    <script>
        layui.use(['form', 'table'], function () {
            var $ = layui.jquery,
                form = layui.form,
                table = layui.table;

            table.render({
                elem: '#currentTableId',
                url: '/Handle/table.ashx',
                toolbar: '#toolbarDemo',
                defaultToolbar: ['filter', 'exports', 'print', {
                    title: '提示',
                    layEvent: 'LAYTABLE_TIPS',
                    icon: 'layui-icon-tips'
                }],
                cols: [
                    [

                        {
                            field: 'Title',
                            width: 150,
                            title: '标题'
                        },
                        {
                            field: 'description',
                            width: 150,
                            title: '描述'
                        },
                        {
                            field: 'StartTime',
                            width: 150,
                            title: '开始时间'
                        },
                        {
                            field: 'EndTime',
                            title: '结束时间',
                            minWidth: 150
                        },
                        {
                            field: 'Status',
                            width: 150,
                            title: '状态',
                            sort: true
                        },

                        {
                            title: '操作',
                            minWidth: 150,
                            toolbar: '#currentTableBar',
                            align: "center"
                        }
                    ]
                ],
                limits: [10, 15, 20, 25, 50, 100],
                limit: 15,
                page: false,
                skin: 'line'
            });

            // 监听搜索操作
            form.on('submit(data-search-btn)', function (data) {
                var result = JSON.stringify(data.field);
                layer.alert(result, {
                    title: '最终的搜索信息'
                });

                //执行搜索重载
                table.reload('currentTableId', {
                    page: {
                        curr: 1
                    },
                    where: {
                        searchParams: result
                    }
                }, 'data');

                return false;
            });

            /**
             * toolbar监听事件
             */
            table.on('toolbar(currentTableFilter)', function (obj) {
                if (obj.event === 'add') { // 监听添加操作
                    var index = layer.open({
                        title: '添加任务',
                        type: 2,
                        shade: 0.2,
                        maxmin: true,
                        shadeClose: true,
                        area: ['80%', '80%'],
                        content: 'Add.aspx',
                    });
                    $(window).on("resize", function () {
                        layer.full(index);
                    });
                } else if (obj.event === 'delete') { // 监听删除操作
                    var checkStatus = table.checkStatus('currentTableId'),
                        data = checkStatus.data;
                    layer.alert(JSON.stringify(data));
                }
            });

            //监听表格复选框选择
            table.on('checkbox(currentTableFilter)', function (obj) {
                console.log(obj)
            });

            //行操作栏
            table.on('tool(currentTableFilter)', function (obj) {
                var data = obj.data;
                if (obj.event === 'edit') {
                    console.log(data)
                    var Title = data.Title;
                    var description = data.description;
                    var StartTime = data.StartTime;
                    var EndTime = data.EndTime;
                    console.log(data.id)
                    var index = layer.open({
                        title: '编辑任务',
                        type: 2,
                        shade: 0.2,
                        maxmin: true,
                        shadeClose: true,
                        area: ['80%', '80%'],
                        content: 'Edit.aspx?Title=' + Title + '&description=' + description + '&StartTime=' + StartTime + '&EndTime=' + EndTime + '&id=' + data.id,
                    });
                    $(window).on("resize", function () {
                        layer.full(index);
                    });
                    return false;
                } else if (obj.event === 'delete') {
                    layer.confirm('真的删除行么', function (index) {
                        obj.del();
                        console.log(obj.data.id)
                        $.post("/Handle/delete.ashx", {
                            id: obj.data.id
                        }

                        );
                        layer.close(index);
                        layer.msg('删除成功')
                    });
                }
                else if (obj.event === 'start') {
                    var targetId = data.id;
                    layer.confirm("开始任务？", function () {
                        $.post("/Handle/start.ashx", { targetId: targetId }, function () {layer.msg("开始任务成功") })

                    })
                }
            });

        });
    </script>

    <script type="text/javascript">
        var chartDom = document.getElementById('echarts-records');
        var myChart = echarts.init(chartDom);
        var option;

        option = {
            tooltip: {
                trigger: 'item'
            },
            legend: {
                top: '10%',
                left: 'center'
            },
            xAxis: {
                type: 'category',
                data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
            },
            yAxis: {
                type: 'value'
            },
            series: [{
        <%
        UserTargetService userTargetService = new UserTargetService();
        string userAccount = Session["userAccount"].ToString();
        int userid = new UserService().getUserid(userAccount);

        int Monday = userTargetService.getWeekFinishCount(userid, "Monday");
        int Tuesday = userTargetService.getWeekFinishCount(userid, "Tuesday");
        int Wednesday = userTargetService.getWeekFinishCount(userid, "Wednesday");
        int Thursday = userTargetService.getWeekFinishCount(userid, "Thursday");
        int Friday = userTargetService.getWeekFinishCount(userid, "Friday");
        int Saturday = userTargetService.getWeekFinishCount(userid, "Saturday");
        int Sunday = userTargetService.getWeekFinishCount(userid, "Sunday");
        %>
                data: [<%=Monday%>, <%=Tuesday%>, <%=Wednesday%>, <%=Thursday%>, <%=Friday%>, <%=Saturday%>, <%=Sunday%>],
               type: 'line'
           }]
       };

        option && myChart.setOption(option);
    </script>
    <script type="text/javascript">
        var chartDom = document.getElementById('echarts-pies');
        var myChart = echarts.init(chartDom);
        var option;

        option = {
            tooltip: {
                trigger: 'item'
            },
            legend: {
                top: '5%',
                left: 'center'
            },
            series: [{
                name: 'Access From',
                type: 'pie',
                radius: ['40%', '70%'],
                avoidLabelOverlap: false,
                itemStyle: {
                    borderRadius: 10,
                    borderColor: '#fff',
                    borderWidth: 2
                },
                label: {
                    show: false,
                    position: 'center'
                },
                emphasis: {
                    label: {
                        show: true,
                        fontSize: '40',
                        fontWeight: 'bold'
                    }
                },
                labelLine: {
                    show: false
                },
                data: [
        <%    
        int noFinish = userTargetService.getNoFinishMyTarget(userid).Count();
        int finish = userTargetService.getFinishMyTarget(userid).Count();
        %>
                    {
                        value: <%=finish%>,
                        name: '已完成'
                    },
                    {
                         value: <%=noFinish%>,
                         name: '未完成'
                     }

                 ]
             }]
         };

        option && myChart.setOption(option);
    </script>
</body>
</html>

